package com.yiwei.jmx.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.allen.library.SuperButton;
import com.yiwei.jmx.R;
import com.yiwei.jmx.api.model.RetrievePasswordV3Model;
import com.yiwei.jmx.base.BaseActivity;
import com.yiwei.jmx.event.FindXueXinSuccessEvent;
import com.yiwei.jmx.view.V19FrameLayout;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.Unbinder;

/**
 * Created by Administrator on 2018/6/10.
 */

public class V3XueXinFindWayActivity extends BaseActivity {

    @BindView(R.id.btn_back)
    ImageView btnBack;
    @BindView(R.id.txt_title)
    TextView txtTitle;
    @BindView(R.id.btn_wechat)
    ImageView btnWechat;
    @BindView(R.id.layout_title)
    V19FrameLayout layoutTitle;
    @BindView(R.id.txt_email_tips)
    TextView txtEmailTips;
    @BindView(R.id.btn_email_way)
    SuperButton btnEmailWay;
    @BindView(R.id.layout_email)
    LinearLayout layoutEmail;
    @BindView(R.id.txt_phone_tips)
    TextView txtPhoneTips;
    @BindView(R.id.btn_phone_way)
    SuperButton btnPhoneWay;
    @BindView(R.id.layout_mobile)
    LinearLayout layoutMobile;
    @BindView(R.id.txt_question_tips)
    TextView txtQuestionTips;
    @BindView(R.id.btn_question_way)
    SuperButton btnQuestionWay;
    @BindView(R.id.layout_question)
    LinearLayout layoutQuestion;
    @BindView(R.id.linearLayout)
    LinearLayout linearLayout;
    private Unbinder unbinder;
    private RetrievePasswordV3Model way_data;
    private String ctoken;
    private String email;
    private String account;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_xuexin_find_way_v3);
        initBar();
        unbinder = ButterKnife.bind(this);
        init();
        EventBus.getDefault().register(this);
    }

    private void init() {

        way_data = getIntent().getParcelableExtra("way_data");
        if (way_data != null) {
            ctoken = way_data.data.ctoken;
            for (int i = 0; i < way_data.data.mode_list.size(); i++) {
                switch (way_data.data.mode_list.get(i).mode) {
                    case "email":
                        layoutEmail.setVisibility(View.VISIBLE);
                        email = way_data.data.mode_list.get(i).value;
                        txtEmailTips.setText(way_data.data.mode_list.get(i).str_value);
                        break;
                    case "mobile":
                        layoutMobile.setVisibility(View.VISIBLE);
                        txtPhoneTips.setText(way_data.data.mode_list.get(i).str_value);
                        break;
                    case "mibao":
                        layoutQuestion.setVisibility(View.VISIBLE);
                        break;
                }
            }
        }
        account = getIntent().getStringExtra("account");
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onEventMainThread(FindXueXinSuccessEvent msg) {
        finish();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        EventBus.getDefault().unregister(this);
        unbinder.unbind();
        unbinder = null;
    }

    @OnClick({R.id.btn_back, R.id.btn_email_way, R.id.btn_phone_way, R.id.btn_question_way})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.btn_back:
                finish();
                break;
            case R.id.btn_email_way:
                Intent intentEmail = new Intent(this, V3XueXinFindByEmailActivity.class);
                intentEmail.putExtra("ctoken", ctoken);
                intentEmail.putExtra("email", email);
                intentEmail.putExtra("account", account);
                startActivity(intentEmail);
                overridePendingTransition(R.anim.right_enter, R.anim.left_out);
                break;
            case R.id.btn_phone_way:
                Intent intentPhone = new Intent(this, V3XueXinFindByPhoneActivity.class);
                intentPhone.putExtra("ctoken", ctoken);
                startActivity(intentPhone);
                overridePendingTransition(R.anim.right_enter, R.anim.left_out);

                break;
            case R.id.btn_question_way:
                Intent intentMibao = new Intent(this, V3XueXinMiBaoQuestionActivity.class);
                intentMibao.putExtra("ctoken", ctoken);
                intentMibao.putExtra("account", account);
                startActivity(intentMibao);
                overridePendingTransition(R.anim.right_enter, R.anim.left_out);
                break;

        }
    }
}
